
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>浮点数的支持 · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-page-footer-ex/style/plugin.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-callouts/plugin.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
        <link rel="stylesheet" href="styles.css">
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="5.2.html" />
    
    
    <link rel="prev" href="PA5.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="./">
            
                <a href="./">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="PA0.html">
            
                <a href="PA0.html">
            
                    
                    PA0 - 世界诞生的前夜: 开发环境配置
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="0.1.html">
            
                <a href="0.1.html">
            
                    
                    Installing a GNU/Linux VM
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="0.2.html">
            
                <a href="0.2.html">
            
                    
                    First Exploration with GNU/Linux
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="0.3.html">
            
                <a href="0.3.html">
            
                    
                    Installing Tools
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4" data-path="0.4.html">
            
                <a href="0.4.html">
            
                    
                    Configuring vim
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.5" data-path="0.5.html">
            
                <a href="0.5.html">
            
                    
                    More Exploration
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.6" data-path="0.6.html">
            
                <a href="0.6.html">
            
                    
                    Transferring Files between host and container
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.7" data-path="0.7.html">
            
                <a href="0.7.html">
            
                    
                    Acquiring Source Code for PAs
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="PA1.html">
            
                <a href="PA1.html">
            
                    
                    PA1 - 开天辟地的篇章: 最简单的计算机
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="1.1.html">
            
                <a href="1.1.html">
            
                    
                    在开始愉快的PA之旅之前
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="1.2.html">
            
                <a href="1.2.html">
            
                    
                    开天辟地的篇章
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="1.3.html">
            
                <a href="1.3.html">
            
                    
                    RTFSC
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="1.4.html">
            
                <a href="1.4.html">
            
                    
                    基础设施
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.5" data-path="1.5.html">
            
                <a href="1.5.html">
            
                    
                    表达式求值
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.6" data-path="1.6.html">
            
                <a href="1.6.html">
            
                    
                    监视点
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.7" data-path="1.7.html">
            
                <a href="1.7.html">
            
                    
                    i386手册
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="PA2.html">
            
                <a href="PA2.html">
            
                    
                    PA2 - 简单复杂的机器: 冯诺依曼计算机系统
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="2.1.html">
            
                <a href="2.1.html">
            
                    
                    不停计算的机器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="2.2.html">
            
                <a href="2.2.html">
            
                    
                    RTFSC(2)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="2.3.html">
            
                <a href="2.3.html">
            
                    
                    程序, 运行时环境与AM
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="2.4.html">
            
                <a href="2.4.html">
            
                    
                    基础设施(2)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5" data-path="2.5.html">
            
                <a href="2.5.html">
            
                    
                    输入输出
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="PA3.html">
            
                <a href="PA3.html">
            
                    
                    PA3 - 穿越时空的旅程: 批处理系统
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="3.1.html">
            
                <a href="3.1.html">
            
                    
                    最简单的操作系统
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="3.2.html">
            
                <a href="3.2.html">
            
                    
                    穿越时空的旅程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="3.3.html">
            
                <a href="3.3.html">
            
                    
                    用户程序和系统调用
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.4" data-path="3.4.html">
            
                <a href="3.4.html">
            
                    
                    文件系统
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.5" data-path="3.5.html">
            
                <a href="3.5.html">
            
                    
                    批处理系统
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="PA4.html">
            
                <a href="PA4.html">
            
                    
                    PA4 - 虚实交错的魔法: 分时多任务
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="4.1.html">
            
                <a href="4.1.html">
            
                    
                    多道程序
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="4.2.html">
            
                <a href="4.2.html">
            
                    
                    虚实交错的魔法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.3" data-path="4.3.html">
            
                <a href="4.3.html">
            
                    
                    超越容量的界限
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.4" data-path="4.4.html">
            
                <a href="4.4.html">
            
                    
                    来自外部的声音
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.5" data-path="4.5.html">
            
                <a href="4.5.html">
            
                    
                    编写不朽的传奇
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="PA5.html">
            
                <a href="PA5.html">
            
                    
                    PA5 - 天下武功唯快不破: 程序与性能
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter active" data-level="1.7.1" data-path="5.1.html">
            
                <a href="5.1.html">
            
                    
                    浮点数的支持
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2" data-path="5.2.html">
            
                <a href="5.2.html">
            
                    
                    通往高速的次元
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.3" data-path="5.3.html">
            
                <a href="5.3.html">
            
                    
                    天下武功唯快不破
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="blank.html">
            
                <a href="blank.html">
            
                    
                    杂项
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.8.1" data-path="why.html">
            
                <a href="why.html">
            
                    
                    为什么要学习计算机系统基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.2" data-path="submit.html">
            
                <a href="submit.html">
            
                    
                    实验提交要求
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.3" data-path="linux.html">
            
                <a href="linux.html">
            
                    
                    Linux入门教程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.4" data-path="man.html">
            
                <a href="man.html">
            
                    
                    man入门教程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.5" data-path="git.html">
            
                <a href="git.html">
            
                    
                    git入门教程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.6" data-path="i386-intro.html">
            
                <a href="i386-intro.html">
            
                    
                    i386手册指令集阅读指南
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.7" data-path="exec.html">
            
                <a href="exec.html">
            
                    
                    指令执行例子
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="." >浮点数的支持</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h2 id="&#x6D6E;&#x70B9;&#x6570;&#x7684;&#x652F;&#x6301;">&#x6D6E;&#x70B9;&#x6570;&#x7684;&#x652F;&#x6301;</h2>
<p>&#x6211;&#x4EEC;&#x5DF2;&#x7ECF;&#x5728;PA3&#x4E2D;&#x628A;&#x4ED9;&#x5251;&#x5947;&#x4FA0;&#x4F20;&#x8FD0;&#x884C;&#x8D77;&#x6765;&#x4E86;, &#x4F46;&#x5374;&#x4E0D;&#x80FD;&#x6218;&#x6597;, &#x8FD9;&#x662F;&#x56E0;&#x4E3A;&#x8FD8;&#x6709;&#x4E00;&#x4E9B;&#x6D6E;&#x70B9;&#x6570;&#x76F8;&#x5173;&#x7684;&#x5DE5;&#x4F5C;&#x9700;&#x8981;&#x5904;&#x7406;.
&#x73B0;&#x5728;&#x5230;&#x4E86;&#x5904;&#x7406;&#x7684;&#x65F6;&#x5019;&#x4E86;.
&#x8981;&#x5728;NEMU&#x4E2D;&#x5B9E;&#x73B0;&#x6D6E;&#x70B9;&#x6307;&#x4EE4;&#x4E5F;&#x4E0D;&#x662F;&#x4E0D;&#x53EF;&#x80FD;&#x7684;&#x4E8B;&#x60C5;.
&#x4F46;&#x5B9E;&#x73B0;&#x6D6E;&#x70B9;&#x6307;&#x4EE4;&#x9700;&#x8981;&#x6D89;&#x53CA;x87&#x67B6;&#x6784;&#x7684;&#x5F88;&#x591A;&#x7EC6;&#x8282;, &#x6839;&#x636E;KISS&#x6CD5;&#x5219;, &#x6211;&#x4EEC;&#x9009;&#x62E9;&#x4E86;&#x4E00;&#x79CD;&#x66F4;&#x7B80;&#x5355;&#x7684;&#x65B9;&#x5F0F;:
&#x6211;&#x4EEC;&#x901A;&#x8FC7;&#x6574;&#x6570;&#x6765;&#x6A21;&#x62DF;&#x5B9E;&#x6570;&#x7684;&#x8FD0;&#x7B97;, &#x8FD9;&#x6837;&#x7684;&#x65B9;&#x6CD5;&#x53EB;<a href="http://en.wikipedia.org/wiki/Binary_scaling" target="_blank">binary scaling</a>.</p>
<p>&#x6211;&#x4EEC;&#x5148;&#x6765;&#x8BF4;&#x660E;&#x5982;&#x4F55;&#x7528;&#x4E00;&#x4E2A;32&#x4F4D;&#x6574;&#x6570;&#x6765;&#x8868;&#x793A;&#x4E00;&#x4E2A;&#x5B9E;&#x6570;.
&#x4E3A;&#x4E86;&#x65B9;&#x4FBF;&#x53D9;&#x8FF0;, &#x6211;&#x4EEC;&#x79F0;&#x7528;binary scaling&#x65B9;&#x6CD5;&#x8868;&#x793A;&#x7684;&#x5B9E;&#x6570;&#x7684;&#x7C7B;&#x578B;&#x4E3A;<code>FLOAT</code>.
&#x6211;&#x4EEC;&#x7EA6;&#x5B9A;&#x6700;&#x9AD8;&#x4F4D;&#x4E3A;&#x7B26;&#x53F7;&#x4F4D;, &#x63A5;&#x4E0B;&#x6765;&#x7684;15&#x4F4D;&#x8868;&#x793A;&#x6574;&#x6570;&#x90E8;&#x5206;, &#x4F4E;16&#x4F4D;&#x8868;&#x793A;&#x5C0F;&#x6570;&#x90E8;&#x5206;,
&#x5373;&#x7EA6;&#x5B9A;&#x5C0F;&#x6570;&#x70B9;&#x5728;&#x7B2C;15&#x548C;&#x7B2C;16&#x4F4D;&#x4E4B;&#x95F4;(&#x4ECE;&#x7B2C;0&#x4F4D;&#x5F00;&#x59CB;).
&#x4ECE;&#x8FD9;&#x4E2A;&#x7EA6;&#x5B9A;&#x53EF;&#x4EE5;&#x770B;&#x5230;, <code>FLOAT</code>&#x7C7B;&#x578B;&#x5176;&#x5B9E;&#x662F;&#x5B9E;&#x6570;&#x7684;&#x4E00;&#x79CD;&#x5B9A;&#x70B9;&#x8868;&#x793A;.</p>
<pre><code>31  30                  16                    0
+----+-------------------+--------------------+
|sign|      integer      |      fraction      |
+----+-------------------+--------------------+
</code></pre><p>&#x8FD9;&#x6837;, &#x5BF9;&#x4E8E;&#x4E00;&#x4E2A;&#x5B9E;&#x6570;<code>a</code>, &#x5B83;&#x7684;<code>FLOAT</code>&#x7C7B;&#x578B;&#x8868;&#x793A;<code>A = a * 2^16</code>(&#x622A;&#x65AD;&#x7ED3;&#x679C;&#x7684;&#x5C0F;&#x6570;&#x90E8;&#x5206;).
&#x4F8B;&#x5982;&#x5B9E;&#x6570;<code>1.2</code>&#x548C;<code>5.6</code>&#x7528;<code>FLOAT</code>&#x7C7B;&#x578B;&#x6765;&#x8FD1;&#x4F3C;&#x8868;&#x793A;, &#x5C31;&#x662F;</p>
<pre><code>1.2 * 2^16 = 78643 = 0x13333
+----+-------------------+--------------------+
| 0  |         1         |        3333        |
+----+-------------------+--------------------+


5.6 * 2^16 = 367001 = 0x59999
+----+-------------------+--------------------+
| 0  |         5         |        9999        |
+----+-------------------+--------------------+
</code></pre><p>&#x800C;&#x5B9E;&#x9645;&#x4E0A;, &#x8FD9;&#x4E24;&#x4E2A;<code>FLOAT</code>&#x7C7B;&#x578B;&#x6570;&#x636E;&#x8868;&#x793A;&#x7684;&#x6570;&#x662F;:</p>
<pre><code>0x13333 / 2^16 = 1.19999695
0x59999 / 2^16 = 5.59999084
</code></pre><p>&#x5BF9;&#x4E8E;&#x8D1F;&#x5B9E;&#x6570;, &#x6211;&#x4EEC;&#x7528;&#x76F8;&#x5E94;&#x6B63;&#x6570;&#x7684;&#x76F8;&#x53CD;&#x6570;&#x6765;&#x8868;&#x793A;, &#x4F8B;&#x5982;<code>-1.2</code>&#x7684;<code>FLOAT</code>&#x7C7B;&#x578B;&#x8868;&#x793A;&#x4E3A;:</p>
<pre><code>-(1.2 * 2^16) = -0x13333 = 0xfffecccd
</code></pre><div class="panel panel-info"><div class="panel-heading"><h3 class="panel-title" id="&#x6BD4;&#x8F83;float&#x548C;float"><i class="fa fa-question-circle"></i> &#x6BD4;&#x8F83;FLOAT&#x548C;float</h3></div><div class="panel-body"><p><code>FLOAT</code>&#x548C;<code>float</code>&#x7C7B;&#x578B;&#x7684;&#x6570;&#x636E;&#x90FD;&#x662F;32&#x4F4D;, &#x5B83;&#x4EEC;&#x90FD;&#x53EF;&#x4EE5;&#x8868;&#x793A;2^32&#x4E2A;&#x4E0D;&#x540C;&#x7684;&#x6570;.
&#x4F46;&#x7531;&#x4E8E;&#x8868;&#x793A;&#x65B9;&#x6CD5;&#x4E0D;&#x4E00;&#x6837;, <code>FLOAT</code>&#x548C;<code>float</code>&#x80FD;&#x8868;&#x793A;&#x7684;&#x6570;&#x96C6;&#x662F;&#x4E0D;&#x4E00;&#x6837;&#x7684;.
&#x601D;&#x8003;&#x4E00;&#x4E0B;, &#x6211;&#x4EEC;&#x7528;<code>FLOAT</code>&#x6765;&#x6A21;&#x62DF;&#x8868;&#x793A;<code>float</code>, &#x8FD9;&#x5176;&#x4E2D;&#x9690;&#x542B;&#x7740;&#x54EA;&#x4E9B;&#x53D6;&#x820D;?</p></div></div>
<p>&#x63A5;&#x4E0B;&#x6765;&#x6211;&#x4EEC;&#x6765;&#x8003;&#x8651;<code>FLOAT</code>&#x7C7B;&#x578B;&#x7684;&#x5E38;&#x89C1;&#x8FD0;&#x7B97;, &#x5047;&#x8BBE;&#x5B9E;&#x6570;<code>a</code>, <code>b</code>&#x7684;<code>FLOAT</code>&#x7C7B;&#x578B;&#x8868;&#x793A;&#x5206;&#x522B;&#x4E3A;<code>A</code>, <code>B</code>.</p>
<ul>
<li>&#x7531;&#x4E8E;&#x6211;&#x4EEC;&#x4F7F;&#x7528;&#x6574;&#x6570;&#x6765;&#x8868;&#x793A;<code>FLOAT</code>&#x7C7B;&#x578B;, <code>FLOAT</code>&#x7C7B;&#x578B;&#x7684;&#x52A0;&#x6CD5;&#x53EF;&#x4EE5;&#x76F4;&#x63A5;&#x7528;&#x6574;&#x6570;&#x52A0;&#x6CD5;&#x6765;&#x8FDB;&#x884C;:<pre><code>A + B = a * 2^16 + b * 2^16 = (a + b) * 2^16
</code></pre></li>
<li>&#x7531;&#x4E8E;&#x6211;&#x4EEC;&#x4F7F;&#x7528;&#x8865;&#x7801;&#x7684;&#x65B9;&#x5F0F;&#x6765;&#x8868;&#x793A;<code>FLOAT</code>&#x7C7B;&#x578B;&#x6570;&#x636E;, &#x56E0;&#x6B64;<code>FLOAT</code>&#x7C7B;&#x578B;&#x7684;&#x51CF;&#x6CD5;&#x7528;&#x6574;&#x6570;&#x51CF;&#x6CD5;&#x6765;&#x8FDB;&#x884C;.<pre><code>A - B = a * 2^16 - b * 2^16 = (a - b) * 2^16
</code></pre></li>
<li><code>FLOAT</code>&#x7C7B;&#x578B;&#x7684;&#x4E58;&#x9664;&#x6CD5;&#x548C;&#x52A0;&#x51CF;&#x6CD5;&#x5C31;&#x4E0D;&#x4E00;&#x6837;&#x4E86;:<pre><code>A * B = a * 2^16 * b * 2^16 = (a * b) * 2^32 != (a * b) * 2^16
</code></pre>&#x4E5F;&#x5C31;&#x662F;&#x8BF4;, &#x76F4;&#x63A5;&#x628A;&#x4E24;&#x4E2A;<code>FLOAT</code>&#x6570;&#x636E;&#x76F8;&#x4E58;&#x5F97;&#x5230;&#x7684;&#x7ED3;&#x679C;&#x5E76;&#x4E0D;&#x7B49;&#x4E8E;&#x76F8;&#x5E94;&#x7684;&#x4E24;&#x4E2A;&#x6D6E;&#x70B9;&#x6570;&#x4E58;&#x79EF;&#x7684;<code>FLOAT</code>&#x8868;&#x793A;.
&#x4E3A;&#x4E86;&#x5F97;&#x5230;&#x6B63;&#x786E;&#x7684;&#x7ED3;&#x679C;, &#x6211;&#x4EEC;&#x9700;&#x8981;&#x5BF9;&#x76F8;&#x4E58;&#x7684;&#x7ED3;&#x679C;&#x8FDB;&#x884C;&#x8C03;&#x6574;: &#x53EA;&#x8981;&#x5C06;&#x7ED3;&#x679C;&#x9664;&#x4EE5;<code>2^16</code>, &#x5C31;&#x80FD;&#x5F97;&#x51FA;&#x6B63;&#x786E;&#x7684;&#x7ED3;&#x679C;&#x4E86;.
&#x9664;&#x6CD5;&#x4E5F;&#x9700;&#x8981;&#x5BF9;&#x7ED3;&#x679C;&#x8FDB;&#x884C;&#x8C03;&#x6574;, &#x81F3;&#x4E8E;&#x5982;&#x4F55;&#x8C03;&#x6574;, &#x5F53;&#x7136;&#x96BE;&#x4E0D;&#x5012;&#x806A;&#x660E;&#x7684;&#x4F60;&#x5566;.</li>
<li>&#x5982;&#x679C;&#x628A;<code>A = a * 2^16</code>&#x770B;&#x6210;&#x4E00;&#x4E2A;&#x6620;&#x5C04;, &#x90A3;&#x4E48;&#x5728;&#x8FD9;&#x4E2A;&#x6620;&#x5C04;&#x7684;&#x4F5C;&#x7528;&#x4E0B;, &#x5173;&#x7CFB;&#x8FD0;&#x7B97;&#x662F;&#x4FDD;&#x5E8F;&#x7684;,
&#x5373;<code>a &lt;= b</code>&#x5F53;&#x4E14;&#x4EC5;&#x5F53;<code>A &lt;= B</code>, &#x6545;<code>FLOAT</code>&#x7C7B;&#x578B;&#x7684;&#x5173;&#x7CFB;&#x8FD0;&#x7B97;&#x53EF;&#x4EE5;&#x7528;&#x6574;&#x6570;&#x7684;&#x5173;&#x7CFB;&#x8FD0;&#x7B97;&#x6765;&#x8FDB;&#x884C;.</li>
</ul>
<p>&#x6709;&#x4E86;&#x8FD9;&#x4E9B;&#x7ED3;&#x8BBA;, &#x8981;&#x7528;<code>FLOAT</code>&#x7C7B;&#x578B;&#x6765;&#x6A21;&#x62DF;&#x5B9E;&#x6570;&#x8FD0;&#x7B97;&#x5C31;&#x5F88;&#x65B9;&#x4FBF;&#x4E86;.
&#x9664;&#x4E86;&#x4E58;&#x9664;&#x6CD5;&#x9700;&#x8981;&#x989D;&#x5916;&#x5B9E;&#x73B0;&#x4E4B;&#x5916;, &#x5176;&#x4F59;&#x8FD0;&#x7B97;&#x90FD;&#x53EF;&#x4EE5;&#x76F4;&#x63A5;&#x4F7F;&#x7528;&#x76F8;&#x5E94;&#x7684;&#x6574;&#x6570;&#x8FD0;&#x7B97;&#x6765;&#x8FDB;&#x884C;. &#x4F8B;&#x5982;</p>
<pre><code class="lang-c"><span class="hljs-keyword">float</span> a = <span class="hljs-number">1.2</span>;
<span class="hljs-keyword">float</span> b = <span class="hljs-number">10</span>;
<span class="hljs-keyword">int</span> c = <span class="hljs-number">0</span>;
<span class="hljs-keyword">if</span> (b &gt; <span class="hljs-number">7.9</span>) {
  c = (a + <span class="hljs-number">1</span>) * b / <span class="hljs-number">2.3</span>;
}
</code></pre>
<p>&#x7528;<code>FLOAT</code>&#x7C7B;&#x578B;&#x6765;&#x6A21;&#x62DF;&#x5C31;&#x662F;</p>
<pre><code class="lang-c">FLOAT a = f2F(<span class="hljs-number">1.2</span>);
FLOAT b = int2F(<span class="hljs-number">10</span>);
<span class="hljs-keyword">int</span> c = <span class="hljs-number">0</span>;
<span class="hljs-keyword">if</span> (b &gt; f2F(<span class="hljs-number">7.9</span>)) {
  c = F2int(F_div_F(F_mul_F((a + int2F(<span class="hljs-number">1</span>)), b), f2F(<span class="hljs-number">2.3</span>)));
}
</code></pre>
<p>&#x5176;&#x4E2D;&#x8FD8;&#x5F15;&#x5165;&#x4E86;&#x4E00;&#x4E9B;&#x7C7B;&#x578B;&#x8F6C;&#x6362;&#x51FD;&#x6570;&#x6765;&#x5B9E;&#x73B0;&#x548C;<code>FLOAT</code>&#x76F8;&#x5173;&#x7684;&#x7C7B;&#x578B;&#x8F6C;&#x6362;.</p>
<p>&#x4ED9;&#x5251;&#x5947;&#x4FA0;&#x4F20;&#x7684;&#x6846;&#x67B6;&#x4EE3;&#x7801;&#x5DF2;&#x7ECF;&#x7528;<code>FLOAT</code>&#x7C7B;&#x578B;&#x5BF9;&#x6D6E;&#x70B9;&#x6570;&#x8FDB;&#x884C;&#x4E86;&#x76F8;&#x5E94;&#x7684;&#x5904;&#x7406;.
&#x4F60;&#x8FD8;&#x9700;&#x8981;&#x5B9E;&#x73B0;&#x4E00;&#x4E9B;&#x548C;<code>FLOAT</code>&#x7C7B;&#x578B;&#x76F8;&#x5173;&#x7684;&#x51FD;&#x6570;:</p>
<pre><code class="lang-c"><span class="hljs-comment">/* navy-apps/apps/pal/include/FLOAT.h */</span>
<span class="hljs-keyword">int32_t</span> F2int(FLOAT a);
<span class="hljs-function">FLOAT <span class="hljs-title">int2F</span><span class="hljs-params">(<span class="hljs-keyword">int</span> a)</span></span>;
<span class="hljs-function">FLOAT <span class="hljs-title">F_mul_int</span><span class="hljs-params">(FLOAT a, <span class="hljs-keyword">int</span> b)</span></span>;
<span class="hljs-function">FLOAT <span class="hljs-title">F_div_int</span><span class="hljs-params">(FLOAT a, <span class="hljs-keyword">int</span> b)</span></span>;
<span class="hljs-comment">/* navy-apps/apps/pal/src/FLOAT/FLOAT.c */</span>
<span class="hljs-function">FLOAT <span class="hljs-title">f2F</span><span class="hljs-params">(<span class="hljs-keyword">float</span> a)</span></span>;
<span class="hljs-function">FLOAT <span class="hljs-title">F_mul_F</span><span class="hljs-params">(FLOAT a, FLOAT b)</span></span>;
<span class="hljs-function">FLOAT <span class="hljs-title">F_div_F</span><span class="hljs-params">(FLOAT a, FLOAT b)</span></span>;
<span class="hljs-function">FLOAT <span class="hljs-title">Fabs</span><span class="hljs-params">(FLOAT a)</span></span>;
</code></pre>
<p>&#x5176;&#x4E2D;<code>F_mul_int()</code>&#x548C;<code>F_div_int()</code>&#x7528;&#x4E8E;&#x8BA1;&#x7B97;&#x4E00;&#x4E2A;<code>FLOAT</code>&#x7C7B;&#x578B;&#x6570;&#x636E;&#x548C;&#x4E00;&#x4E2A;&#x6574;&#x578B;&#x6570;&#x636E;&#x7684;&#x79EF;/&#x5546;,
&#x8FD9;&#x4E24;&#x79CD;&#x7279;&#x6B8A;&#x60C5;&#x51B5;&#x53EF;&#x4EE5;&#x5FEB;&#x901F;&#x8BA1;&#x7B97;&#x51FA;&#x7ED3;&#x679C;, &#x4E0D;&#x9700;&#x8981;&#x5C06;&#x6574;&#x578B;&#x6570;&#x636E;&#x5148;&#x8F6C;&#x5316;&#x6210;<code>FLOAT</code>&#x7C7B;&#x578B;&#x518D;&#x8FDB;&#x884C;&#x8FD0;&#x7B97;.</p>
<p>&#x4E8B;&#x5B9E;&#x4E0A;, &#x6211;&#x4EEC;&#x5E76;&#x6CA1;&#x6709;&#x8003;&#x8651;&#x8BA1;&#x7B97;&#x7ED3;&#x679C;&#x6EA2;&#x51FA;&#x7684;&#x60C5;&#x51B5;,
&#x4E0D;&#x8FC7;&#x4ED9;&#x5251;&#x5947;&#x4FA0;&#x4F20;&#x4E2D;&#x7684;&#x6D6E;&#x70B9;&#x6570;&#x7ED3;&#x679C;&#x90FD;&#x53EF;&#x4EE5;&#x5728;<code>FLOAT</code>&#x7C7B;&#x578B;&#x4E2D;&#x8868;&#x793A;, &#x6240;&#x4EE5;&#x4F60;&#x53EF;&#x4EE5;&#x4E0D;&#x5173;&#x5FC3;&#x6EA2;&#x51FA;&#x7684;&#x95EE;&#x9898;.
&#x5982;&#x679C;&#x4F60;&#x4E0D;&#x653E;&#x5FC3;, &#x4F60;&#x53EF;&#x4EE5;&#x5728;&#x4E0A;&#x8FF0;&#x51FD;&#x6570;&#x7684;&#x5B9E;&#x73B0;&#x4E2D;&#x63D2;&#x5165;assertion&#x6765;&#x6355;&#x6349;&#x6EA2;&#x51FA;&#x9519;&#x8BEF;.</p>
<div class="panel panel-warning"><div class="panel-heading"><h3 class="panel-title" id="&#x5B9E;&#x73B0;binary-scaling"><i class="fa fa-edit"></i> &#x5B9E;&#x73B0;binary scaling</h3></div><div class="panel-body"><p>&#x5B9E;&#x73B0;&#x4E0A;&#x8FF0;&#x51FD;&#x6570;&#x6765;&#x5728;&#x4ED9;&#x5251;&#x5947;&#x4FA0;&#x4F20;&#x4E2D;&#x5BF9;&#x6D6E;&#x70B9;&#x6570;&#x64CD;&#x4F5C;&#x8FDB;&#x884C;&#x6A21;&#x62DF;.
&#x5B9E;&#x73B0;&#x6B63;&#x786E;&#x540E;, &#x4F60;&#x5C31;&#x53EF;&#x4EE5;&#x5728;&#x4ED9;&#x5251;&#x5947;&#x4FA0;&#x4F20;&#x4E2D;&#x6210;&#x529F;&#x8FDB;&#x884C;&#x6218;&#x6597;&#x4E86;.</p></div></div>
<footer class="page-footer-ex"> <span class="page-footer-ex-copyright"> By <a href="https://sashimi-yzh.github.io/" target="_blank">Zihao Yu</a>, &#x91C7;&#x7528;<a href="http://creativecommons.org/licenses/by-nc-sa/3.0/cn/" target="_blank">&#x77E5;&#x8BC6;&#x5171;&#x4EAB; &#x7F72;&#x540D;-&#x975E;&#x5546;&#x4E1A;&#x6027;&#x4F7F;&#x7528;-&#x76F8;&#x540C;&#x65B9;&#x5F0F;&#x5171;&#x4EAB; 3.0 &#x4E2D;&#x56FD;&#x5927;&#x9646; &#x8BB8;&#x53EF;&#x534F;&#x8BAE;</a>&#x53D1;&#x5E03; </span> &#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0; <span class="page-footer-ex-footer-update"> &#x6B64;&#x9875;&#x9762;&#x4FEE;&#x8BA2;&#x4E8E;:  2019-05-03 14:52:05 </span> </footer>
                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="PA5.html" class="navigation navigation-prev " aria-label="Previous page: PA5 - 天下武功唯快不破: 程序与性能">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="5.2.html" class="navigation navigation-next " aria-label="Next page: 通往高速的次元">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"浮点数的支持","level":"1.7.1","depth":2,"next":{"title":"通往高速的次元","level":"1.7.2","depth":2,"path":"5.2.md","ref":"5.2.md","articles":[]},"previous":{"title":"PA5 - 天下武功唯快不破: 程序与性能","level":"1.7","depth":1,"path":"PA5.md","ref":"PA5.md","articles":[{"title":"浮点数的支持","level":"1.7.1","depth":2,"path":"5.1.md","ref":"5.1.md","articles":[]},{"title":"通往高速的次元","level":"1.7.2","depth":2,"path":"5.2.md","ref":"5.2.md","articles":[]},{"title":"天下武功唯快不破","level":"1.7.3","depth":2,"path":"5.3.md","ref":"5.3.md","articles":[]}]},"dir":"ltr"},"config":{"gitbook":"3.x.x","theme":"default","variables":{},"plugins":["localized-footer","page-footer-ex","callouts"],"pluginsConfig":{"callouts":{"flag":{"alert":"success","picto":"fa-flag"},"question":{"alert":"info","picto":"fa-question-circle"},"info":{"alert":"info","picto":"fa-info-circle"},"todo":{"alert":"warning","picto":"fa-edit"},"caution":{"alert":"danger","picto":"fa-bullhorn"},"danger":{"alert":"danger","picto":"fa-exclamation"},"showTypeInHeader":false},"page-footer-ex":{"copyright":"By [Zihao Yu](https://sashimi-yzh.github.io/), 采用[知识共享 署名-非商业性使用-相同方式共享 3.0 中国大陆 许可协议](http://creativecommons.org/licenses/by-nc-sa/3.0/cn/)发布","markdown":true,"update_format":"YYYY-MM-DD HH:mm:ss","update_label":"此页面修订于: "},"search":{},"localized-footer":{"filename":"FOOTER.md","hline":"true"},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"fontsettings":{"theme":"white","family":"sans","size":2},"highlight":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles.css","pdf":"styles.css"}},"file":{"path":"5.1.md","mtime":"2019-05-03T06:52:05.581Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2019-05-03T10:26:23.925Z"},"basePath":".","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="gitbook/gitbook.js"></script>
    <script src="gitbook/theme.js"></script>
    
        
        <script src="gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

